function getWeek(dateTime) {
    let temptTime = dateTime
        //周几
    let weekday = temptTime.getDay() || 7
        //周1+5天=周六
    temptTime.setDate(temptTime.getDate() - weekday + 1 + 5)
    let firstDay = new Date(temptTime.getFullYear(), 0, 1)
    let dayOfWeek = firstDay.getDay()
    let spendDay = 1
    if (dayOfWeek != 0) {
        spendDay = 7 - dayOfWeek + 1
    }
    firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay)
    let d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 86400000)
    let result = Math.ceil(d / 7)
    return result + 1
}
var time = theRequest.BeginTime;
var year = time.slice(0, 4);
console.log(year);
console.log(time);
$('header nav ul li').html(year + '年' + '第' + getWeek(new Date(`"${time}"`)) + '周报告')

var settings = {
    "url": "http://58.210.112.60:38102/Wechat/Api/LoginWechat",
    "method": "POST",
    "timeout": 0,
    "headers": {
        "Content-Type": "application/json",
        "Accept": "*/*",
    },
    "data": JSON.stringify({
        "wechatId": openid
    }),
};
$.ajax(settings).done(function(response) {
    //血压数据
    $.ajax({
            url: `${Url}/Wechat/Api/PeriodNewBP?IdentityNo=${theRequest.IdentityNo}&BeginTime=${theRequest.BeginTime}&EndTime=${theRequest.EndTime}`,
            type: 'get',
            datatype: 'json',
            headers: {
                'Authorization': response.data.Authorization
            },
            // data: responseData,
            async: false,
            success: function(res) {
                const data = res.data.NewBPItems;
                var LeftDiastolic = [];
                var RightSystolic = [];
                var RightDiastolic = [];
                var LeftSystolic = [];
                var CheckDate = [];
                for (let key in data) {
                    var con = data[key]

                    LeftDiastolic.push(con.LeftDiastolic);
                    RightSystolic.push(con.RightSystolic);
                    RightDiastolic.push(con.RightDiastolic);
                    LeftSystolic.push(con.LeftSystolic);
                    CheckDate.push(con.CheckDate);

                }
                const LeftSystolicLength = data.filter(con => con.LeftSystolic <= 90 || con.LeftSystolic > 140).length;
                const LeftDiastolicLength = data.filter(con => con.LeftDiastolic <= 60 || con.LeftDiastolic > 90).length;
                const RightSystolicLength = data.filter(con => con.RightSystolic <= 90 || con.RightSystolic > 140).length;
                const RightDiastolicLength = data.filter(con => con.RightDiastolic <= 60 || con.RightDiastolic > 90).length;
                const result = LeftSystolicLength + LeftDiastolicLength + RightSystolicLength + RightDiastolicLength;

                let teplhtml = `<tr><td>${data.length}</td><td>${result}</td></tr>`
                $('#newBp').html(teplhtml);




                var myChart1 = echarts.init(document.getElementById('main1'));

                option1 = {
                    title: {
                        text: '血压检测数据',
                        subtext: '收缩压参考值:90~140mmHg',
                        x: 'right',

                    },
                    grid: {


                        top: "30%",
                        right: "10%",
                        bottom: '10%',
                        //     width: "66%",
                        left: "10%",
                        //     containLabel: true,
                        //     height: "55%"
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        y: 'top',
                        data: ['左收缩压', '右收缩压'],

                    },
                    xAxis: {
                        data: CheckDate,
                        show: false,
                    },
                    yAxis: {
                        max: 200,
                        min: 30
                    },
                    series: [{
                        name: '左收缩压',
                        type: 'line',
                        data: LeftSystolic,
                        markLine: {
                            symbol: ['none', 'none'], //去掉箭头
                            itemStyle: {
                                normal: {
                                    lineStyle: {
                                        type: 'dashed',
                                        color: { //设置渐变
                                            type: 'linear',
                                            // x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0,
                                                color: 'red ' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: 'red' // 100% 处的颜色
                                            }],
                                            global: false // 缺省为 false
                                        }
                                    },
                                }
                            },
                            data: [{
                                yAxis: 90,
                            }, {
                                yAxis: 140,
                            }]
                        },

                    }, {
                        name: '右收缩压',
                        type: 'line',
                        data: RightSystolic,
                    }],
                    color: ['#3366CC', '#FFCC99'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'line'
                        }
                    },

                };
                myChart1.setOption(option1);


                var myChart6 = echarts.init(document.getElementById('main6'));

                option6 = {
                    title: {
                        text: '血压检测数据',
                        subtext: '舒缩压参考值:60-90mmHg',
                        x: 'right',

                    },
                    grid: {


                        top: "30%",
                        right: "10%",
                        bottom: '10%',
                        left: "10%",
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        y: 'top',
                        data: ['左舒缩压', '右舒缩压'],

                    },
                    xAxis: {
                        data: CheckDate,
                        show: false,
                    },
                    yAxis: {
                        max: 200,
                        min: 30
                    },
                    series: [{
                        name: '左舒缩压',
                        type: 'line',
                        data: LeftDiastolic,
                        markLine: {
                            symbol: ['none', 'none'], //去掉箭头
                            itemStyle: {
                                normal: {
                                    lineStyle: {
                                        type: 'dashed',
                                        color: { //设置渐变
                                            type: 'linear',
                                            // x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0,
                                                color: 'red ' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: 'red' // 100% 处的颜色
                                            }],
                                            global: false // 缺省为 false
                                        }
                                    },
                                }
                            },
                            data: [{
                                yAxis: 60,
                            }, {
                                yAxis: 90,
                            }]
                        },

                    }, {
                        name: '右舒缩压',
                        type: 'line',
                        data: RightDiastolic,
                    }],
                    color: ['#3366CC', '#FFCC99'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'line'
                        }
                    },

                };
                myChart6.setOption(option6);
            }
        })
        //血氧数据
    $.ajax({
            url: `${Url}/Wechat/Api/PeriodOxygenLevel?IdentityNo=${theRequest.IdentityNo}&BeginTime=${theRequest.BeginTime}&EndTime=${theRequest.EndTime}`,
            type: 'get',
            datatype: 'json',
            headers: {
                'Authorization': response.data.Authorization
            },
            // data: responseData,
            async: false,
            success: function(res) {
                const data = res.data.OxygenLevelItems;
                var CheckDate = [];
                var Oxygen = [];
                var Pulse = [];
                for (let key in data) {
                    var con = data[key];
                    CheckDate.push(con.CheckDate);
                    Oxygen.push(con.Oxygen);
                    Pulse.push(con.Pulse);
                };
                const OxygenLength = data.filter(con => con.Oxygen < 96).length;
                const PulseLength = data.filter(con => con.Pulse < 60 || con.Pulse > 100).length;
                const result = OxygenLength + PulseLength;

                let teplhtml = `<tr><td>${data.length}</td><td>${result}</td></tr>`;
                $('#oxygenLevel').html(teplhtml);
                var myChart1 = echarts.init(document.getElementById('main2'));

                option1 = {
                    title: {
                        text: '血氧检测数据',
                        subtext: '饱和度:96-100%',
                        x: 'right',

                    },
                    grid: {
                        top: "30%",
                        right: "10%",
                        bottom: '10%',
                        left: "10%",
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        y: 'top',
                        data: ['饱和率'],

                    },
                    xAxis: {
                        data: CheckDate,
                        show: false,
                    },
                    yAxis: {
                        max: 100,
                        min: 80
                    },
                    series: [{
                        name: '饱和率',
                        type: 'line',
                        data: Oxygen,
                        markLine: {
                            symbol: ['none', 'none'], //去掉箭头
                            itemStyle: {
                                normal: {
                                    lineStyle: {
                                        type: 'dashed',
                                        color: { //设置渐变
                                            type: 'linear',
                                            // x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0,
                                                color: 'red ' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: 'red' // 100% 处的颜色
                                            }],
                                            global: false // 缺省为 false
                                        }
                                    },
                                }
                            },
                            data: [{
                                yAxis: 96,
                            }, {
                                yAxis: 100,
                            }]
                        },

                    }],
                    color: ['#3366CC', '#FFCC99'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'line'
                        }
                    },

                };
                myChart1.setOption(option1);


                var myChart7 = echarts.init(document.getElementById('main7'));

                option7 = {
                    title: {
                        text: '血氧检测数据',
                        subtext: '心率参考值:60-100次/分',
                        x: 'right',

                    },
                    grid: {
                        top: "30%",
                        right: "10%",
                        bottom: '10%',
                        left: "10%",
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        y: 'top',
                        data: ['心率'],

                    },
                    xAxis: {
                        data: CheckDate,
                        show: false,
                    },
                    yAxis: {
                        max: 200,
                        min: 30
                    },
                    series: [{
                        name: '心率',
                        type: 'line',
                        data: Pulse,
                        markLine: {
                            symbol: ['none', 'none'], //去掉箭头
                            itemStyle: {
                                normal: {
                                    lineStyle: {
                                        type: 'dashed',
                                        color: { //设置渐变
                                            type: 'linear',
                                            // x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0,
                                                color: 'red ' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: 'red' // 100% 处的颜色
                                            }],
                                            global: false // 缺省为 false
                                        }
                                    },
                                }
                            },
                            data: [{
                                yAxis: 60,
                            }, {
                                yAxis: 100,
                            }]
                        },

                    }],
                    color: ['#3366CC', '#FFCC99'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'line'
                        }
                    },

                };
                myChart7.setOption(option7);
            }
        })
        //血糖数据
    $.ajax({
            url: `${Url}/Wechat/Api/PeriodBloodGlucose?IdentityNo=${theRequest.IdentityNo}&BeginTime=${theRequest.BeginTime}&EndTime=${theRequest.EndTime}`,
            type: 'get',
            datatype: 'json',
            headers: {
                'Authorization': response.data.Authorization
            },
            // data: responseData,
            async: false,
            success: function(res) {
                var num6 = res.data.BloodGlucoseItems;
                var CheckDate = [];
                var Glucose = [];
                if (num6.length > 0) {
                    // $('#tabletext').css('display', 'block')
                    for (let key in num6) {
                        var con = num6[key]
                        CheckDate.push(con.CheckDate);
                        Glucose.push(con.Glucose);
                    }
                } else {
                    // $('#tabletext').css('display', 'none')
                };
                const GlucoseLength = num6.filter(con => con.Glucose < 3.61 || con.Glucose > 6.11).length;
                const result = GlucoseLength;
                let teplhtml = `<tr><td>${num6.length}</td><td>${result}</td></tr>`
                $('#bloodglucose').html(teplhtml);



                var startLength = 100 - (5 / CheckDate.length * 100);
                var myChart2 = echarts.init(document.getElementById('main3'));
                option2 = {
                    title: {
                        text: '血糖检测数据',
                        subtext: '血糖参考值:3.61--6.11mmol/L',
                        x: 'right',
                    },
                    grid: {
                        top: "30%",
                        right: "10%",
                        bottom: '20%',
                        //     width: "66%",
                        left: "10%",
                        //     containLabel: true,
                        //     height: "55%"
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        y: 'top',
                        data: ['血糖数值'],

                    },
                    xAxis: {
                        show: false,
                        data: CheckDate,
                        axisLabel: {
                            interval: 0,
                        },

                    },
                    yAxis: {
                        max: 10,
                        min: 0

                    },
                    series: [{
                        name: '血糖数值',
                        type: 'line',
                        data: Glucose,
                        markLine: {
                            symbol: ['none', 'none'], //去掉箭头
                            itemStyle: {
                                normal: {
                                    lineStyle: {
                                        type: 'dashed',
                                        color: { //设置渐变
                                            type: 'linear',
                                            // x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0,
                                                color: 'red ' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: 'red' // 100% 处的颜色
                                            }],
                                            global: false // 缺省为 false
                                        }
                                    },
                                }
                            },
                            data: [{
                                yAxis: 3.61,
                            }, {
                                yAxis: 6.11,
                            }]
                        },

                    }, ],
                    color: ['#3366CC'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'line'
                        }
                    },
                    dataZoom: [ //滑动条
                        {
                            type: 'inside',
                            realtime: true,
                            start: startLength,
                            end: 100,
                            startValue: 0
                        }
                    ],
                };
                myChart2.setOption(option2);



            }
        })
        //体温
    $.ajax({
            url: `${Url}/Wechat/Api/PeriodTemperature?IdentityNo=${theRequest.IdentityNo}&BeginTime=${theRequest.BeginTime}&EndTime=${theRequest.EndTime}`,
            type: 'get',
            datatype: 'json',
            headers: {
                'Authorization': response.data.Authorization
            },
            // data: responseData,
            async: false,
            success: function(res) {
                var num6 = res.data.TemperatureItems;
                var CheckDate = [];
                var Temperature = [];
                if (num6.length > 0) {
                    $('#tabletext').css('display', 'block')
                    for (let key in num6) {
                        var con = num6[key]
                        var title = '';
                        CheckDate.push(con.CheckDate);
                        Temperature.push(con.Temperature);
                    }
                } else {
                    $('#tabletext').css('display', 'none')
                }
                const TemperatureLength = num6.filter(con => con.Temperature < 35.7 || con.Temperature > 37.3).length;
                const result = TemperatureLength

                let teplhtml = `<tr><td>${num6.length}</td><td>${result}</td></tr>`
                $('#temperature').html(teplhtml);

                var startLength = 100 - (2 / CheckDate.length * 100);
                var myChart1 = echarts.init(document.getElementById('main4'));

                option1 = {
                    title: {
                        text: '体温检测数据',
                        subtext: '额度参考值:35.7°C~37.3°C',
                        x: 'right',

                    },
                    grid: {


                        top: "30%",
                        right: "0%",
                        bottom: '10%',
                        //     width: "66%",
                        left: "10%",
                        //     containLabel: true,
                        //     height: "55%"
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        y: 'top',
                        data: ['额度'],

                    },
                    xAxis: {
                        data: CheckDate,
                        show: false,
                        axisLabel: {
                            interval: 0,
                        },
                    },
                    yAxis: {
                        max: 43,
                        min: 30,
                    },
                    series: [{
                        name: '额度',
                        type: 'line',
                        data: Temperature,
                        markLine: {
                            symbol: ['none', 'none'], //去掉箭头
                            itemStyle: {
                                normal: {
                                    lineStyle: {
                                        type: 'dashed',
                                        color: { //设置渐变
                                            type: 'linear',
                                            // x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0,
                                                color: 'red ' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: 'red' // 100% 处的颜色
                                            }],
                                            global: false // 缺省为 false
                                        }
                                    },
                                }
                            },
                            data: [{
                                yAxis: 35.7,
                            }, {
                                yAxis: 37.3,
                            }]
                        },

                    }],
                    color: ['#3366CC'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'line'
                        }
                    },
                    dataZoom: [ //滑动条
                        {
                            type: 'inside',
                            realtime: true,
                            start: startLength,
                            end: 100,
                            startValue: 0
                        }
                    ],

                };
                myChart1.setOption(option1);
            }
        })
        //心电
    $.ajax({
        url: `${Url}/Wechat/Api/PeriodECG?IdentityNo=${theRequest.IdentityNo}&BeginTime=${theRequest.BeginTime}&EndTime=${theRequest.EndTime}`,
        type: 'get',
        datatype: 'json',
        headers: {
            'Authorization': response.data.Authorization
        },
        // data: responseData,
        async: false,
        success: function(res) {
            //收缩压
            var HeartRate = [];
            var num6 = res.data.ECGItems;
            var CheckDate = [];
            if (num6.length > 0) {
                for (let key in num6) {
                    var con = num6[key]
                        //   var title = '';
                        //   CheckDate.push(con.CheckDate);
                    HeartRate.push(con.HeartRate);
                    CheckDate.push(con.CheckDate);

                    //   $('tbody').prepend(`<tr><td>${con.CheckDate}</td><td>${con.Oxygen}</td><td>${con.Pulse}</td><td>${title}</td></tr>`);
                    //   $('tbody tr').prepend();
                }
            } else {
                $('#tabletext').css('display', 'none')
            }

            const HeartRateLength = num6.filter(con => con.HeartRate < 60 || con.HeartRate > 100).length;
            const result = HeartRateLength
            let teplhtml = `<tr><td>${num6.length}</td><td>${result}</td></tr>`
            $('#ecg').html(teplhtml);

            var myChart1 = echarts.init(document.getElementById('main5'));
            option1 = {
                title: {
                    text: '心率检测数据',
                    subtext: '心率脉率:60~100次/分',
                    x: 'right',

                },
                grid: {


                    top: "30%",
                    right: "0%",
                    bottom: '10%',
                    left: "10%",
                },

                legend: {
                    orient: 'vertical',
                    x: 'left',
                    y: 'top',
                    data: ['心率'],

                },
                xAxis: {
                    show: false,
                    data: [CheckDate],
                },
                yAxis: {
                    max: 200,
                    min: 0
                },
                series: [{
                    name: '心率',
                    type: 'line',
                    dataIndex: 1,
                    data: HeartRate,
                    //   data: [1, 2],
                    markLine: {
                        symbol: ['none', 'none'], //去掉箭头
                        itemStyle: {
                            normal: {
                                lineStyle: {
                                    type: 'dashed',
                                    color: { //设置渐变
                                        type: 'linear',
                                        x: 0,
                                        y: 0,
                                        x2: 0,
                                        y2: 1,
                                        colorStops: [{
                                            offset: 0,
                                            color: 'red ' // 0% 处的颜色
                                        }, {
                                            offset: 1,
                                            color: 'red' // 100% 处的颜色
                                        }],
                                        global: false // 缺省为 false
                                    }
                                },
                            }
                        },
                        data: [{
                            yAxis: 60,
                        }, {
                            yAxis: 100,
                        }]
                    },

                }],
                color: ['#3366CC'],
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'line'
                    }
                },
            };
            myChart1.setOption(option1);



        }
    })
});



var NowMonth = theRequest.BeginTime
var WeekMonth = theRequest.EndTime